package com.patelski.magic.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Lob;
import javax.persistence.OrderBy;

import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

@Entity
@Table(name = "EDITIONS")
public class Edition implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1506900589404205913L;
	private String id;
	private String name;
	private Date releaseDate;
	private String blockName;
	private byte[] expansionSymbol;
	private Integer sortOrder;
	private Integer printSize;
	private String description;
	private List<Card> theSet = new ArrayList<Card>(0);
	private EditionCategorie editionCategorie;

	public Edition() {
	}

	public Edition(String name, Date releaseDate, String blockName) {
		this.name = name;
		this.releaseDate = releaseDate;
		this.blockName = blockName;
	}

	public Edition(String id, String name, Date releaseDate, String blockName) {
		this(name, releaseDate, blockName);
		this.id = id;
	}

	@Id
	@Column(name = "ID", unique = true, nullable = false, length = 4)
	@Length(max = 4)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "NAME", nullable = false, length = 45)
	@NotNull
	@Length(max = 45)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}


	@Column(name = "RELEASEDATE")
	public Date getReleaseDate() {
		return releaseDate;
	}

	public void setReleaseDate(Date releaseDate) {
		this.releaseDate = releaseDate;
	}

	@Column(name = "BLOCK_NAME", nullable = true, length = 45)
	@Length(max = 45)
	public String getBlockName() {
		return blockName;
	}

	public void setBlockName(String blockName) {
		this.blockName = blockName;
	}

    @Lob
	@Column(name = "EXPANSION_SYMBOL", nullable = true)
	@Basic(fetch = FetchType.LAZY)
	public byte[] getExpansionSymbol() {
		return expansionSymbol;
	}

	public void setExpansionSymbol(byte[] expansionSymbol) {
		this.expansionSymbol = expansionSymbol;
	}

	@Column(name = "SORT_ORDER", nullable = true)
	public Integer getSortOrder() {
		return sortOrder;
	}

	public void setSortOrder(Integer sortOrder) {
		this.sortOrder = sortOrder;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "edition")
	@OrderBy("foil desc, collectorNumber")
	public List<Card> getTheSet() {
		return theSet;
	}

	public void setTheSet(List<Card> theSet) {
		this.theSet = theSet;
	}

	@Column(name = "PRINT_SIZE", nullable = true)
	public Integer getPrintSize() {
		return printSize;
	}

	public void setPrintSize(Integer printSize) {
		this.printSize = printSize;
	}

	@Column(name = "DESCRIPTION", columnDefinition = "text")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "EDITION_CATEGORIE", nullable = true)
//	@NotNull
	public EditionCategorie getEditionCategorie() {
    	return editionCategorie;
    }

	public void setEditionCategorie(EditionCategorie editionCategorie) {
    	this.editionCategorie = editionCategorie;
    }


}
